package cn.bytecollege.controller;

import cn.bytecollege.entity.RoomCategory;
import cn.bytecollege.service.RoomCategoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RoomCategoryUpdateController",value = "/roomCategoryUpdate")
public class RoomCategoryUpdateController extends HttpServlet {


    private RoomCategoryService roomCategoryService=null;
    public RoomCategoryUpdateController(){
        roomCategoryService=new RoomCategoryService();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String msg=null;
        //接收参数
        String categoryName=request.getParameter("category");
        String id=request.getParameter("roomCategoryId");
        //方法执行到这说明更改的分类可用
        RoomCategory roomCategory=new RoomCategory();
        roomCategory.setRoomCategoryId(Integer.valueOf(id));
        roomCategory.setRoomCategoryName(categoryName);
        roomCategoryService.update(roomCategory);
        //跳转到列表页面
        response.sendRedirect(request.getContextPath()+"/roomCategoryList");
    }
}
